package com.jams.goodox.widget;

import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;

import com.jams.goodox.listen.DialogActionListener;

/**
 * Created by jams on 2016/7/11.
 * 系统对话框 AlertDialog
 * ***
 * Tel: ***
 */

public class PromptBuilderDialog {
    private final AlertDialog.Builder builder;
    private DialogActionListener dialogActionListener;

    public PromptBuilderDialog(Context context) {
        this.builder = new AlertDialog.Builder(context);
    }

    //设置title,使用字符串
    public PromptBuilderDialog setTitle(CharSequence title) {
        builder.setTitle(title);
        return this;
    }

    public PromptBuilderDialog setTitle(@StringRes int titleId) {
        builder.setTitle(titleId);
        return this;
    }

    public PromptBuilderDialog setActionClickListener(DialogActionListener dialogActionListener) {
        this.dialogActionListener = dialogActionListener;
        return this;
    }

    //设置title,使用字符串
    public PromptBuilderDialog setContent(CharSequence content) {
        builder.setMessage(content);
        return this;
    }

    public PromptBuilderDialog setContent(@StringRes int contentId) {
        builder.setMessage(contentId);
        return this;
    }

    //设置title,使用字符串
    public PromptBuilderDialog setPositive(CharSequence positive) {
        builder.setPositiveButton(positive, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogActionListener != null) {
                    dialogActionListener.confirm(dialog, which);
                }
            }
        });
        return this;
    }

    public PromptBuilderDialog setPositive(@StringRes int positiveId) {
        builder.setPositiveButton(positiveId, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogActionListener != null) {
                    dialogActionListener.confirm(dialog, which);
                }
            }
        });
        return this;
    }

    public PromptBuilderDialog setNegative(String negative) {
        builder.setNegativeButton(negative, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogActionListener != null) {
                    dialogActionListener.cancel(dialog, which);
                }
            }
        });
        return this;
    }

    public PromptBuilderDialog setNegative(@StringRes int negativeId) {
        builder.setNegativeButton(negativeId, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogActionListener != null) {
                    dialogActionListener.cancel(dialog, which);
                }
            }
        });
        return this;
    }

    public PromptBuilderDialog setCancelAble(boolean bool){
        builder.setCancelable(bool);
        return this;
    }

    public PromptBuilderDialog show(){
         builder.show();
        return this;
    }
}
